# 自定义热点新闻颜色过滤器
from flask import session, current_app, g


def hot_news_filter(value):
    if value == 1:
        return 'first'
    if value == 2:
        return 'second'
    if value == 3:
        return 'third'
    return None


from functools import wraps


# 定义登录装饰器
def login_require(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        # 1.获取用户信息
        user_id = session.get('user_id')
        # 2.根据user_id 取出用户
        user = None
        if user_id:
            try:
                from news_info_app.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        # 3.将user对象封装到g
        g.user = user
        return func(*args, **kwargs)
    return wrapper


if __name__ == '__main__':
    a = hot_news_filter(5)
    print(a)
